/*    */ package net.sourceforge.appgen.generator;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.FileWriter;
/*    */ import java.io.Writer;
/*    */ import net.sourceforge.appgen.model.Entity;
/*    */ import net.sourceforge.appgen.model.GenerationInformation;
/*    */ import org.apache.velocity.Template;
/*    */ import org.apache.velocity.VelocityContext;
/*    */ import org.apache.velocity.app.Velocity;
/*    */ 
/*    */ public class ResourcePropertiesFileGenerator extends OnceFileGenerator
/*    */ {
/*    */   public static final String TEMPLATE = "resourceProperties.vm";
/* 37 */   private boolean aleradyGenerate = false;
/*    */ 
/*    */   public ResourcePropertiesFileGenerator(GenerationInformation generationInformation) {
/* 40 */     super(generationInformation);
/*    */   }
/*    */ 
/*    */   public File generateFile(Entity entity, String template, File file) throws Exception
/*    */   {
/* 45 */     Velocity.init(this.properties);
/*    */ 
/* 47 */     Template modelTemplate = Velocity.getTemplate(template);
/*    */ 
/* 49 */     VelocityContext context = new VelocityContext();
/* 50 */     context.put("outputDir", this.outputDir);
/* 51 */     context.put("packageName", this.packageName);
/*    */ 
/* 53 */     Writer writer = null;
/*    */     try
/*    */     {
/* 56 */       writer = new FileWriter(file);
/*    */ 
/* 58 */       modelTemplate.merge(context, writer);
/*    */     } catch (Exception e) {
/* 60 */       throw e;
/*    */     } finally {
/* 62 */       if (writer != null)
/*    */         try {
/* 64 */           writer.close();
/*    */         }
/*    */         catch (Exception localException1)
/*    */         {
/*    */         }
/*    */     }
/* 70 */     return file;
/*    */   }
/*    */ 
/*    */   public File generate(Entity entity) throws Exception
/*    */   {
/* 75 */     if (!this.aleradyGenerate) {
/* 76 */       this.aleradyGenerate = true;
/*    */ 
/* 78 */       return generateFile(entity, getTemplate(), getFile(entity));
/*    */     }
/*    */ 
/* 81 */     return null;
/*    */   }
/*    */ 
/*    */   public File getFile(Entity entity)
/*    */   {
/* 86 */     return new File(getDirectory(), "resource.properties");
/*    */   }
/*    */ 
/*    */   public File getDirectory()
/*    */   {
/* 91 */     return new File(this.outputDir.getPath() + File.separator + "WebContent" + File.separator + "WEB-INF" + File.separator + "properties");
/*    */   }
/*    */ 
/*    */   public String getTemplate()
/*    */   {
/* 96 */     return "resourceProperties.vm";
/*    */   }
/*    */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.generator.ResourcePropertiesFileGenerator
 * JD-Core Version:    0.6.0
 */